home *** CD-ROM | disk | FTP | other *** search
/ Network CD 2 / Network CD - Volume 2.iso / programs / internet / mail / smailsr2.lha / SMail / src / RCS / mail.c,v < prev    next >
Encoding:
Text File  |  1993-11-30  |  21.2 KB  |  1,186 lines

  1. head    2.3;
  2. access;
  3. symbols
  4.     C_2:2.3
  5.     C_1:1.13;
  6. locks; strict;
  7. comment    @ * @;
  8.  
  9.  
  10. 2.3
  11. date    93.11.30.18.20.45;    author Aussem;    state Exp;
  12. branches;
  13. next    2.2;
  14.  
  15. 2.2
  16. date    93.11.29.23.07.44;    author Aussem;    state Exp;
  17. branches;
  18. next    2.1;
  19.  
  20. 2.1
  21. date    93.11.23.19.58.39;    author Aussem;    state Exp;
  22. branches;
  23. next    1.13;
  24.  
  25. 1.13
  26. date    93.11.06.16.00.10;    author Aussem;    state Exp;
  27. branches;
  28. next    1.12;
  29.  
  30. 1.12
  31. date    93.11.02.20.12.42;    author Aussem;    state Exp;
  32. branches;
  33. next    1.11;
  34.  
  35. 1.11
  36. date    93.10.31.20.10.53;    author Aussem;    state Exp;
  37. branches;
  38. next    1.10;
  39.  
  40. 1.10
  41. date    93.10.23.21.22.49;    author Aussem;    state Exp;
  42. branches;
  43. next    1.9;
  44.  
  45. 1.9
  46. date    93.10.21.21.17.05;    author Aussem;    state Exp;
  47. branches;
  48. next    1.8;
  49.  
  50. 1.8
  51. date    93.10.16.14.54.51;    author Aussem;    state Exp;
  52. branches;
  53. next    1.7;
  54.  
  55. 1.7
  56. date    93.10.13.21.41.42;    author Aussem;    state Exp;
  57. branches;
  58. next    1.6;
  59.  
  60. 1.6
  61. date    93.10.02.00.14.38;    author Aussem;    state Exp;
  62. branches;
  63. next    1.5;
  64.  
  65. 1.5
  66. date    93.09.30.22.21.34;    author Aussem;    state Exp;
  67. branches;
  68. next    1.4;
  69.  
  70. 1.4
  71. date    93.09.30.21.07.03;    author Aussem;    state Exp;
  72. branches;
  73. next    1.3;
  74.  
  75. 1.3
  76. date    93.09.23.22.44.57;    author Aussem;    state Exp;
  77. branches;
  78. next    1.2;
  79.  
  80. 1.2
  81. date    93.09.18.16.47.47;    author Aussem;    state Exp;
  82. branches;
  83. next    1.1;
  84.  
  85. 1.1
  86. date    93.09.11.15.01.16;    author Aussem;    state Exp;
  87. branches;
  88. next    ;
  89.  
  90.  
  91. desc
  92. @Local mailer for smail
  93. @
  94.  
  95.  
  96. 2.3
  97. log
  98. @defines and getuid() for AMITCP insert
  99. @
  100. text
  101. @/*
  102.  * emulation of the unix mail command
  103.  * Just append it to the mail-folder
  104.  *
  105.  *
  106.  * This program is free software; you can redistribute it and/or
  107.  * modify it under the terms of the GNU General Public License as
  108.  * published by the Free Software Foundation; either version 2 of
  109.  * the License, or (at your option) any later version.
  110.  *
  111.  * This program is distributed in the hope that it will be useful,
  112.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  113.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  114.  * General Public License for more details.
  115.  *
  116.  * You should have received a copy of the GNU General Public License
  117.  * along with this program; if not, write to the Free Software
  118.  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  119.  *
  120.  * $Log: mail.c,v $
  121.  * Revision 2.2  1993/11/29  23:07:44  Aussem
  122.  * mail uses now netsupport.library for allocation and get
  123.  * config data
  124.  *
  125.  * Revision 2.1  1993/11/23  19:58:39  Aussem
  126.  * Version 2.0 check in
  127.  *
  128.  * Revision 1.13  1993/11/06  16:00:10  Aussem
  129.  * mail now don't stop at once if the delivering fails
  130.  *
  131.  * Revision 1.12  1993/11/02  20:12:42  Aussem
  132.  * MUFS routines insert
  133.  *
  134.  * Revision 1.11  1993/10/31  20:10:53  Aussem
  135.  * submitt a bigger stack
  136.  *
  137.  * Revision 1.10  1993/10/23  21:22:49  Aussem
  138.  * mail now uses the mail folder directly (uumail:user)
  139.  *
  140.  * Revision 1.9  1993/10/21  21:17:05  Aussem
  141.  * MailReadyCmd will be started via run <nil: >nil:
  142.  * only if t:mailrdy does not exists
  143.  * if the mail folder is locked, mail will be wait until
  144.  * the mail folder is unlocked
  145.  *
  146.  * Revision 1.8  1993/10/16  14:54:51  Aussem
  147.  * cosmetic changes
  148.  *
  149.  * Revision 1.7  1993/10/13  21:41:42  Aussem
  150.  * mail supports now more than one address for each
  151.  * invocation. This is needed for Maxrmaillength!=0 !
  152.  *
  153.  * Revision 1.6  1993/10/02  00:14:38  Aussem
  154.  * MailReadyCmd keyword in uulib:condif is supported by mail and mail_axsh
  155.  *
  156.  * Revision 1.5  1993/09/30  22:21:34  Aussem
  157.  * if env:MAILTONOEXIST mail will deliver a mail although the user does not
  158.  * exists on the site.
  159.  *
  160.  * Revision 1.4  1993/09/30  21:07:03  Aussem
  161.  * mail wait now 6 minutes to open uumail:<mail-folder>
  162.  *
  163.  * Revision 1.3  1993/09/23  22:44:57  Aussem
  164.  * removes uumail:<file>.o before backup uumail:<file>
  165.  *
  166.  * Revision 1.2  1993/09/18  16:47:47  Aussem
  167.  * put the "normal" and axsh version in this file (set define AXSH
  168.  * for the AXSh Version)
  169.  *
  170.  * Revision 1.1  1993/09/11  15:01:16  Aussem
  171.  * Initial revision
  172.  *
  173.  *
  174.  */
  175.  
  176. static char     *rcsid="$Id: mail.c,v 2.2 1993/11/29 23:07:44 Aussem Exp Aussem $";
  177.  
  178. #include <stdio.h>
  179. #include <string.h>
  180. #include <stdlib.h>
  181. #include <dos.h>
  182. #include <proto/dos.h>
  183. #include <pragmas/dos_pragmas.h>
  184. #include <proto/exec.h>
  185. #include <pragmas/exec_pragmas.h>
  186.  
  187. #ifdef AXSH
  188. #include "axsh/iomodes.h"
  189. #include "axsh/misc.h"
  190. #include "axsh/users.h"
  191. static struct User usr;
  192. #endif
  193.  
  194. #ifdef NETSUPPORT
  195. #include <libraries/netsupport.h>
  196. #include <proto/netsupport.h>
  197. #include <pragmas/netsupport_pragmas.h>
  198. #include <exec/memory.h>
  199. struct NetSupportLibrary *NetSupportBase=NULL;
  200. #define malloc(size)    AllocMemPooled((size), MEMF_PUBLIC)
  201. #define calloc(size,nr) AllocMemPooled((size)*(nr), MEMF_CLEAR|MEMF_PUBLIC)
  202. #define free(ptr)       FreeMemPooled(ptr)
  203. #define findconfig(field,default_string) GetConfigEntry(NULL, field, default_string)
  204. #endif
  205.  
  206. extern struct DosLibrary *DOSBase;
  207.  
  208. /* should be large enough */
  209. long __stack=20000L;
  210.  
  211. /* global Vars for this modul */
  212. static const char *uumail = "UUMAIL:";
  213. static const char *version = "$VER: mail V2.0 © 1993 by Ralph-Thomas Aussem ("__DATE__","__TIME__")";
  214. static const int maxretry = 30;
  215. static const int retrysecs = 20;
  216. static char *argv0 = "mail";
  217.  
  218. /* prototypes */
  219. static char *readfile (char *);
  220. static long filelength (char *);
  221. static void sleep (unsigned long time);
  222.  
  223. #ifdef NETSUPPORT
  224. /*
  225.  *  setup_netsupport(): setup the netsupport library
  226.  *
  227.  *  return: 0 for error
  228.  *          else okay
  229.  *
  230.  */
  231. int setup_netsupport(void)
  232. {
  233. if(!NetSupportBase)
  234.     {
  235.     NetSupportBase=(struct NetSupportLibrary *)OpenLibrary(NETSUPPORTNAME,0L);
  236.     if(!NetSupportBase)
  237.         {
  238. #ifdef DEBUG
  239.         printf("%s: unable to open %s Version >= %d\n",argv0,NETSUPPORTNAME,0L);
  240. #endif
  241.         return(0);
  242.        }
  243.    }
  244.  
  245. return(1);
  246. }
  247.  
  248. /*
  249.  *  kill_netsupport(): close the Netsupport library
  250.  *
  251.  */
  252. void kill_netsupport(void)
  253. {
  254. if(NetSupportBase)
  255.     {
  256.     CloseLibrary((struct Library *)NetSupportBase);
  257.     NetSupportBase=NULL;
  258.     }
  259. }
  260.  
  261. #endif
  262.  
  263. #ifdef AXSH
  264. int
  265. getuid (char *name)
  266. {
  267.   if (search_userdata ("AXsh:etc/passwd", &usr, 0, name) == -1)        /* if user not found */
  268.         return(0);
  269. return(1);
  270. }
  271. #endif
  272.  
  273. #ifdef AMITCP
  274. int
  275. getuid (char *name)
  276. {
  277. void *getpwnam(char *);
  278.  
  279. if(getpwnam(name)==NULL)
  280.     return(0);
  281. return(1);
  282. }
  283. #endif
  284.  
  285. #ifdef MUFS
  286. #include <proto/multiuser.h>
  287. #include <pragmas/multiuser_pragmas.h>
  288. #include <libraries/multiuser.h>
  289.  
  290. struct muBase *muBase=NULL;
  291. struct muUserInfo *ui=NULL;
  292.  
  293. int setup_mufs(void);
  294. void kill_mufs(void);
  295.  
  296. int getuid(char *name)
  297. {
  298. strcpy(ui->UserID,name);
  299. if(muGetUserInfo(ui,muKeyType_UserID)==NULL)
  300.     {
  301.     return(0);
  302.     }
  303. return(1);
  304. }
  305.  
  306. int setup_mufs(void)
  307. {
  308. if(!muBase)
  309.     {
  310.     muBase=(struct muBase *)OpenLibrary(MULTIUSERNAME,MULTIUSERVERSION);
  311.     if(!muBase)
  312.         {
  313. #ifdef DEBUG
  314.         printf("%s: unable to open %s Version >= %d\n",argv0,MULTIUSERNAME,MULTIUSERVERSION);
  315. #endif
  316.         return(0);
  317.        }
  318.    }
  319.  
  320. if(!ui)
  321.     {
  322.     ui=muAllocUserInfo();
  323.     if(!ui)
  324.         {
  325.         kill_mufs();
  326. #ifdef DEBUG
  327.         printf("%s: unable to alloc mem\n");
  328. #endif
  329.         return(NULL);
  330.         }
  331.     }
  332. return(1);
  333. }
  334.  
  335. void kill_mufs(void)
  336. {
  337. if(ui)
  338.     muFreeUserInfo(ui);
  339. if(muBase)
  340.     CloseLibrary((struct Library *)muBase);
  341. }
  342. #endif /* MUFS */
  343.  
  344. /*
  345.  * sleep():
  346.  * wait <time> seconds
  347.  */
  348. static void
  349. sleep (unsigned long time)
  350. {
  351.   Delay (50L * time);
  352. }
  353.  
  354. /*
  355.  * filelength():
  356.  * returns the length of file <fname>
  357.  * it returns -1 if the file does not exists or locked
  358.  * by someone else
  359.  */
  360. static
  361. long
  362. filelength (char *fname)
  363. {
  364.   struct FileInfoBlock __aligned fileinfo;
  365.   long groesse;
  366.   BPTR fp;
  367.  
  368.   fp=Open(fname,MODE_OLDFILE);
  369.   if(!fp)
  370.       {
  371.       LONG error=IoErr();
  372.  
  373.    if(error == ERROR_OBJECT_IN_USE)
  374.        return(-2);
  375.    if(error == ERROR_OBJECT_NOT_FOUND)
  376.        return(-1);
  377.    }
  378.   ExamineFH (fp, &fileinfo);
  379.   groesse = (long) fileinfo.fib_Size;
  380.   Close (fp);
  381.   return (groesse);
  382. }
  383.  
  384. long getpid(void)
  385. {
  386. struct Process *proc;
  387.  
  388. Forbid();
  389. proc=(struct Process *)FindTask(NULL);
  390. Permit();
  391. if(proc)return(proc->pr_TaskNum);
  392. return(0);
  393. }
  394.  
  395. int lock_with_file(char *lockfilename)
  396. {
  397.     FILE *file;
  398.     char buf[BUFSIZ];
  399.  
  400.     while( ( file = fopen( lockfilename, "r" ) ) != NULL )
  401.     {
  402.         fgets( buf, sizeof(buf), file );
  403.         fclose( file );
  404. #ifdef DEBUG
  405.         printf( "Mail locked by proc '%s'. Waiting 10 secs\n", buf);
  406. #endif
  407.         sleep( 10 );
  408.     }
  409.  
  410. #ifdef DEBUG
  411.     printf("locking Mail.\n");
  412. #endif
  413.     if( ( file = fopen( lockfilename, "w" ) ) == NULL ) return -1;
  414.     fprintf( file, "%d\n", getpid() );
  415.     fclose( file );
  416.     return 0;
  417. }
  418.  
  419. int unlock_with_file( char *lockfilename )
  420. {
  421. #ifdef DEBUG
  422.     printf("unlock Mail.\n");
  423. #endif
  424.     return remove( lockfilename );
  425. }
  426.  
  427. /*
  428.  * readfile():
  429.  * read file <filename> and returns the buffer
  430.  *
  431.  */
  432. static
  433. char *
  434. readfile (char *filename)
  435. {
  436.   char *puf;
  437.   size_t len, read;
  438.   FILE *fp;
  439.  
  440. #ifdef DEBUG
  441.     printf("Reading %s.\n",filename);
  442. #endif
  443.  
  444.   if (!filename)
  445.     return (NULL);
  446.  
  447.   len = filelength (filename);
  448.   if (len < 1)
  449.     {
  450.       printf ("\n%s: unable to open file %s", argv0, filename);
  451.       return (NULL);
  452.     }
  453.  
  454.   puf = malloc ((len + 1) * sizeof (char));
  455.   if (!puf)
  456.     {
  457.       printf ("\n%s: unable to allocate %d Bytes", argv0, (len + 1) * sizeof (char));
  458.       free (puf);
  459.       return (NULL);
  460.     }
  461.  
  462.   fp = fopen (filename, "r");
  463.   if (!fp)
  464.     {
  465.       printf ("\n%s: unable to open file %s", argv0, filename);
  466.       free (puf);
  467.       return (NULL);
  468.     }
  469.  
  470.   read = fread (puf, len, 1, fp) * len;
  471.   if (read != len)
  472.     {
  473.       printf ("\n%s: unable to read from %s %d (%d) bytes", argv0, filename, len, read);
  474.       free (puf);
  475.       fclose (fp);
  476.       return (NULL);
  477.     }
  478.   puf[len]='\0';
  479.   fclose (fp);
  480.   return (puf);
  481. }
  482.  
  483. #ifndef NETSUPPORT
  484. #define CTLZ    ('z'&0x1F)
  485. static char *ConfBuf = NULL;
  486.  
  487. char *
  488. findconfig(field,def)
  489. char *field,def;
  490. {
  491.     char *str;
  492.     short flen = strlen(field);
  493.  
  494.     /*
  495.      *    load config file if not already loaded
  496.      */
  497.  
  498.     if (ConfBuf == NULL) {
  499.     FILE *fi;
  500.     fi = fopen("S:UUConfig", "r");
  501.     if (fi == NULL)
  502.         fi = fopen("UULIB:Config", "r");
  503.     if (fi) {
  504.         long buflen;
  505.         fseek(fi, 0L, 2);
  506.         buflen = ftell(fi);
  507.         fseek(fi, 0L, 0);
  508.         if (buflen > 0 && (ConfBuf = malloc(buflen + 1))) {
  509.         fread(ConfBuf, buflen, 1, fi);
  510.         ConfBuf[buflen] = CTLZ;     /*    can't use \0 */
  511.         for (str = ConfBuf; *str && *str != CTLZ; ++str) {
  512.             char *bup;
  513.             if (*str == '\n') {     /*  make separate strs */
  514.             *str = 0;
  515.                         /*    remove white space at end */
  516.             for (bup = str - 1; bup >= ConfBuf && (*bup == ' ' || *bup == 9); --bup)
  517.                 *bup = 0;
  518.             }
  519.         }
  520.         } else {
  521.         ConfBuf = NULL;
  522.         }
  523.         fclose(fi);
  524.     }
  525.     }
  526.     if (ConfBuf == NULL)
  527.     return(def);
  528.  
  529.     /*
  530.      *    Search ConfBuf for Field<space/tab>
  531.      */
  532.  
  533.     for (str = ConfBuf; *str != CTLZ; str += strlen(str) + 1) {
  534.     if (*str == 0 || *str == '#')
  535.         continue;
  536.     if (strnicmp(str, field, flen) == 0 && (str[flen] == ' ' || str[flen] == '\t')) {
  537.         str += flen;
  538.         while (*str == ' ' || *str == 9)
  539.         ++str;
  540.         return(str);
  541.     }
  542.     }
  543.     return(def);
  544. }
  545. #endif
  546.  
  547. /*
  548.  * MAIN
  549.  */
  550. int
  551. main (int argc, char *argv[])
  552. {
  553.   FILE *fp;
  554.   char file[128],lockfile[128], puf[128], *text, *cmd,*address;
  555.   long len;
  556.   int retry,i,fail=0;
  557.  
  558.   argv0 = argv[0];
  559.  
  560. #ifdef NETSUPPORT
  561.   setup_netsupport();
  562. #endif
  563.  
  564. #ifdef MUFS
  565.   setup_mufs();
  566. #endif
  567.  
  568.   if (argc < 3)
  569.     {
  570.       printf ("usage %s mail-file address0 .. addressn\n", argv0);
  571.       exit (10);
  572.     }
  573.  
  574.   text = readfile (argv[1]);
  575.   if (!text)
  576.       {
  577.       /* error messages are generated by readfile() */
  578.       remove (file);
  579.         unlock_with_file(lockfile);
  580.       exit (10);
  581.       }
  582.  
  583.  
  584.   for(i=2;i<argc;i++)
  585.   {
  586.   address=argv[i];
  587.   retry=0;
  588.   printf("sending mail to '%s'...",address);
  589.  
  590.   strcpy (file, uumail);
  591.   strcat (file, address);
  592.   len=filelength(file);
  593.  
  594.   while(len==-2)
  595.     {
  596.        len=filelength(file);
  597.       retry++;
  598.       printf ("\n%s: unable to open %s (%d retries done), waiting %d secs", argv0, file, retry-1,retrysecs);
  599.       sleep (retrysecs);
  600.    }
  601.  
  602. #if defined(AXSH) || defined(MUFS) || defined(AMITCP)
  603.   if(!getuid(address))
  604.     {
  605.       if(getenv("MAILTONOEXIST")==NULL)
  606.           {
  607.           printf (" No user '%s' exists\n",address);
  608.           fail=1;
  609.          continue;
  610.           }
  611.     }
  612.  
  613. #else
  614.   if(len==-1)
  615.     {
  616.       if(getenv("MAILTONOEXIST")==NULL)
  617.           {
  618.           printf (" No mail-folder for user '%s'\n",address);
  619.           fail=1;
  620.          continue;
  621.           }
  622.     }
  623. #endif
  624.  
  625.   strcpy (lockfile, "T:");
  626.   strcat (lockfile, address);
  627.   strcat (lockfile,".lck");
  628.   lock_with_file(lockfile);
  629.  
  630.   fp = fopen (file, "a");
  631.   if (!fp)
  632.     {
  633.       printf ("\n%s: Unable to open the backup mail-folder for %s (%s)", argv0, address, file);
  634.       remove (file);
  635.         unlock_with_file(lockfile);
  636.       exit (10);
  637.     }
  638.  
  639.   len = strlen (text);
  640.   if ((fwrite (text, len, 1, fp) * len) != len)
  641.     {
  642.       printf ("\n%s: Error appending mail to mail-folder %s", argv0, file);
  643.       fclose (fp);
  644.       remove (file);
  645.         unlock_with_file(lockfile);
  646.       exit (10);
  647.     }
  648.  
  649.   fclose (fp);
  650.   unlock_with_file(lockfile);
  651.  
  652.   cmd=findconfig("MailReadyCmd","");
  653.   if(cmd[0]!='\0')
  654.       {
  655.       if(filelength("T:MailRdy")==-1)
  656.           {
  657.             strcpy(puf,"echo >T:MailRdy");
  658.             system(puf);
  659.             strcpy(puf,"run <nil: >nil: ");
  660.               strcat(puf,cmd);
  661.               system(puf);
  662.        }
  663.       }
  664.   putchar('\n');
  665.   }
  666.  
  667.   if(text)
  668.       free (text);
  669.  
  670. #ifdef MUFS
  671.   kill_mufs();
  672. #endif
  673.  
  674. #ifdef NETSUPPORT
  675.   kill_netsupport();
  676. #endif
  677.  
  678.   if(fail)
  679.       exit (5);
  680.   exit(0);
  681. }
  682. @
  683.  
  684.  
  685. 2.2
  686. log
  687. @mail uses now netsupport.library for allocation and get
  688. config data
  689. @
  690. text
  691. @d21 4
  692. d76 1
  693. a76 1
  694. static char     *rcsid="$Id: mail.c,v 2.1 1993/11/23 19:58:39 Aussem Exp Aussem $";
  695. d173 12
  696. d502 1
  697. a502 1
  698. #if defined(AXSH) || defined(MUFS)
  699. @
  700.  
  701.  
  702. 2.1
  703. log
  704. @Version 2.0 check in
  705. @
  706. text
  707. @d21 3
  708. d72 1
  709. a72 1
  710. static char     *rcsid="$Id: mail.c,v 1.13 1993/11/06 16:00:10 Aussem Exp Aussem $";
  711. d90 11
  712. d109 1
  713. a109 1
  714. static const char *version = "$VER: mail V1.4 © 1993 by Ralph-Thomas Aussem ("__DATE__","__TIME__")";
  715. d118 40
  716. a157 1
  717. char * findconfig(char *);
  718. a181 3
  719. if(!setup_mufs())
  720.     return(0);
  721.  
  722. d241 1
  723. a241 1
  724.  * it returns -1 if the file does not exists or locked 
  725. d367 1
  726. d372 2
  727. a373 2
  728. findconfig(field)
  729. char *field;
  730. d411 1
  731. a411 1
  732.     return(NULL);
  733. d427 1
  734. a427 1
  735.     return(NULL);
  736. d429 1
  737. d444 8
  738. d536 2
  739. a537 2
  740.   cmd=findconfig("MailReadyCmd");
  741.   if(cmd)
  742. d553 1
  743. d557 5
  744. @
  745.  
  746.  
  747. 1.13
  748. log
  749. @mail now don't stop at once if the delivering fails
  750. @
  751. text
  752. @d21 3
  753. d69 1
  754. a69 1
  755. static char     *rcsid="$Id: mail.c,v 1.12 1993/11/02 20:12:42 Aussem Exp Aussem $";
  756. @
  757.  
  758.  
  759. 1.12
  760. log
  761. @MUFS routines insert
  762. @
  763. text
  764. @d21 3
  765. d66 1
  766. a66 1
  767. static char     *rcsid="$Id: mail.c,v 1.11 1993/10/31 20:10:53 Aussem Exp Aussem $";
  768. d385 1
  769. a385 1
  770.   int retry,i;
  771. d429 2
  772. a430 1
  773.           exit (20);
  774. d440 2
  775. a441 1
  776.           exit (20);
  777. d493 3
  778. a495 1
  779.   exit (0);
  780. @
  781.  
  782.  
  783. 1.11
  784. log
  785. @submitt a bigger stack
  786. @
  787. text
  788. @d21 3
  789. d63 1
  790. a63 1
  791. static char     *rcsid="$Id: mail.c,v 1.10 1993/10/23 21:22:49 Aussem Exp Aussem $";
  792. d110 62
  793. d420 1
  794. a420 1
  795. #ifdef AXSH
  796. d485 3
  797. @
  798.  
  799.  
  800. 1.10
  801. log
  802. @mail now uses the mail folder directly (uumail:user)
  803. @
  804. text
  805. @d21 3
  806. d60 1
  807. a60 1
  808. static char     *rcsid="$Id: mail.c,v 1.9 1993/10/21 21:17:05 Aussem Exp Aussem $";
  809. d81 3
  810. d86 1
  811. a86 1
  812. static const char *version = "$VER: mail V1.3 © 1993 by Ralph-Thomas Aussem ("__DATE__","__TIME__")";
  813. @
  814.  
  815.  
  816. 1.9
  817. log
  818. @MailReadyCmd will be started via run <nil: >nil:
  819. only if t:mailrdy does not exists
  820. if the mail folder is locked, mail will be wait until
  821. the mail folder is unlocked
  822. @
  823. text
  824. @d21 6
  825. d57 1
  826. a57 1
  827. static char     *rcsid="$Id: mail.c,v 1.8 1993/10/16 14:54:51 Aussem Exp Aussem $";
  828. d311 1
  829. a311 1
  830.   int rc, retry,i;
  831. a374 23
  832.  
  833.   /* remove uumail:<file>.o */
  834.   strcpy (puf, file);
  835.   strcat (puf, ".o");
  836.   remove(puf);
  837.  
  838.   if(len>0)
  839.       {
  840.       strcpy (puf, "copy ");
  841.       strcat (puf, file);
  842.       strcat (puf, " to ");
  843.       strcat (puf, file);
  844.       strcat (puf, ".o");
  845.       rc = system (puf);
  846.       if (rc)
  847.         {
  848.           printf ("\n%s: Unable to create backup file (%s)", argv0, puf);
  849.             unlock_with_file(lockfile);
  850.           exit (10);
  851.         }
  852.    }
  853.   strcat (file, ".o");
  854.  
  855. d393 1
  856. a394 18
  857.  
  858.   strcpy (puf, "copy ");
  859.   strcat (puf, file);
  860.   strcat (puf, " to ");
  861.   strcat (puf, file);
  862.   len = strlen (puf);
  863.   if (len >= 2)
  864.     puf[len - 2] = '\0';
  865.   rc = system (puf);
  866.   if (rc)
  867.     {
  868.       printf ("\n%s: Unable to rename backup file (%s)", argv0, puf);
  869.       remove (file);
  870.         unlock_with_file(lockfile);
  871.       exit (10);
  872.     }
  873.  
  874.   remove (file);
  875. d409 1
  876. a409 1
  877.   putc('\n',fp);
  878. @
  879.  
  880.  
  881. 1.8
  882. log
  883. @cosmetic changes
  884. @
  885. text
  886. @d21 3
  887. d51 1
  888. a51 1
  889. static char     *rcsid="$Id: mail.c,v 1.7 1993/10/13 21:41:42 Aussem Exp Aussem $";
  890. d74 1
  891. a74 1
  892. static const char *version = "$VER: mail V1.2 © 1993 by Ralph-Thomas Aussem ("__DATE__","__TIME__")";
  893. a115 1
  894.   struct FileLock *lock;
  895. d117 6
  896. d124 6
  897. a129 3
  898.   if (!(lock = (struct FileLock *) Lock (fname, ACCESS_READ)))
  899.     return (-1);
  900.   Examine ((BPTR) lock, &fileinfo);
  901. d131 1
  902. a131 1
  903.   UnLock ((BPTR) lock);
  904. d201 1
  905. a201 1
  906.       printf ("%s: unable to open file %s\n", argv0, filename);
  907. d208 1
  908. a208 1
  909.       printf ("%s: unable to allocate %d Bytes\n", argv0, (len + 1) * sizeof (char));
  910. d216 1
  911. a216 1
  912.       printf ("%s: unable to open file %s\n", argv0, filename);
  913. d224 1
  914. a224 1
  915.       printf ("%s: unable to read from %s %d (%d) bytes\n", argv0, filename, len, read);
  916. d315 10
  917. a330 5
  918.   strcpy (lockfile, "T:");
  919.   strcat (lockfile, address);
  920.   strcat (lockfile,".lck");
  921.   lock_with_file(lockfile);
  922.  
  923. d333 1
  924. d335 7
  925. a341 1
  926.   len=filelength(file);
  927. a348 1
  928.             unlock_with_file(lockfile);
  929. a358 1
  930.             unlock_with_file(lockfile);
  931. d363 7
  932. a376 1
  933.  
  934. d385 1
  935. a385 1
  936.           printf ("%s: Unable to create backup file (%s)\n", argv0, puf);
  937. d392 1
  938. a392 20
  939.   text = readfile (argv[1]);
  940.   if (!text)
  941.     {
  942.       /* error messages are generated by readfile() */
  943.       remove (file);
  944.         unlock_with_file(lockfile);
  945.       exit (10);
  946.     }
  947.  
  948.   do
  949.     {
  950.       retry++;
  951.       fp = fopen (file, "a");
  952.       if (fp)
  953.             break;
  954.       printf ("%s: unable to open %s, waiting %d secs\n", argv0, file, retrysecs);
  955.       sleep (retrysecs);
  956.     }
  957.   while (retry < maxretry);
  958.  
  959. d395 1
  960. a395 1
  961.       printf ("%s: Unable to open the backup mail-folder for %s (%s)\n", argv0, address, file);
  962. a396 2
  963.       if (text)
  964.             free (text);
  965. d404 1
  966. a404 1
  967.       printf ("%s: Error appending mail to mail-folder %s\n", argv0, file);
  968. a405 2
  969.       if (text)
  970.             free (text);
  971. a410 2
  972.   if (text)
  973.     free (text);
  974. d422 1
  975. a422 1
  976.       printf ("%s: Unable to rename backup file (%s)\n", argv0, puf);
  977. d430 1
  978. d433 11
  979. a443 1
  980.       system(cmd);
  981. d445 3
  982. @
  983.  
  984.  
  985. 1.7
  986. log
  987. @mail supports now more than one address for each
  988. invocation. This is needed for Maxrmaillength!=0 !
  989. @
  990. text
  991. @d21 4
  992. d48 1
  993. a48 1
  994. static char     *rcsid="$Id: mail.c,v 1.6 1993/10/02 00:14:38 Aussem Exp Aussem $";
  995. d71 1
  996. a71 1
  997. static const char *version = "$VER: mail V1.1 © 1993 by Ralph-Thomas Aussem ("__DATE__","__TIME__")";
  998. d368 1
  999. d379 1
  1000. a379 1
  1001.     break;
  1002. @
  1003.  
  1004.  
  1005. 1.6
  1006. log
  1007. @MailReadyCmd keyword in uulib:condif is supported by mail and mail_axsh
  1008. @
  1009. text
  1010. @d21 3
  1011. d44 1
  1012. a44 1
  1013. static char     *rcsid="$Id: mail.c,v 1.5 1993/09/30 22:21:34 Aussem Exp Aussem $";
  1014. d288 1
  1015. a288 1
  1016.   char file[128],lockfile[128]="T:", puf[128], *text, *cmd;
  1017. d290 1
  1018. a290 1
  1019.   int rc, retry = 0;
  1020. d294 1
  1021. a294 1
  1022.   if (argc == 4)
  1023. d296 1
  1024. a296 1
  1025.       printf ("%s: only mail to local host possible\nPlease use your sendmail program !\n", argv0);
  1026. d299 6
  1027. a304 5
  1028.   if (argc != 3)
  1029.     {
  1030.       printf ("usage %s mail-file address\n", argv0);
  1031.       exit (10);
  1032.     }
  1033. d306 2
  1034. a307 1
  1035.   strcat (lockfile, argv[2]);
  1036. d312 1
  1037. a312 1
  1038.   strcat (file, argv[2]);
  1039. d317 1
  1040. a317 1
  1041.   if(!getuid(argv[2]))
  1042. d321 1
  1043. a321 1
  1044.           printf (" No user '%s' exists\n",argv[2]);
  1045. d332 1
  1046. a332 1
  1047.           printf (" No mail-folder for user '%s'\n",argv[2]);
  1048. d382 1
  1049. a382 1
  1050.       printf ("%s: Unable to open the backup mail-folder for %s (%s)\n", argv0, argv[2], file);
  1051. d426 1
  1052. @
  1053.  
  1054.  
  1055. 1.5
  1056. log
  1057. @if env:MAILTONOEXIST mail will deliver a mail although the user does not
  1058. exists on the site.
  1059. @
  1060. text
  1061. @d21 4
  1062. d41 1
  1063. a41 1
  1064. static char     *rcsid="$Id: mail.c,v 1.4 1993/09/30 21:07:03 Aussem Exp Aussem $";
  1065. d73 1
  1066. d216 62
  1067. d285 1
  1068. a285 1
  1069.   char file[128],lockfile[128]="T:", puf[128], *text;
  1070. d418 3
  1071. @
  1072.  
  1073.  
  1074. 1.4
  1075. log
  1076. @mail wait now 6 minutes to open uumail:<mail-folder>
  1077. @
  1078. text
  1079. @d21 3
  1080. d37 1
  1081. a37 1
  1082. static char     *rcsid="$Id: mail.c,v 1.3 1993/09/23 22:44:57 Aussem Exp Aussem $";
  1083. d247 6
  1084. a252 3
  1085.       printf (" No user '%s' exists\n",argv[2]);
  1086.         unlock_with_file(lockfile);
  1087.       exit (20);
  1088. d258 6
  1089. a263 3
  1090.       printf (" No mail-folder for user '%s'\n",argv[2]);
  1091.         unlock_with_file(lockfile);
  1092.       exit (20);
  1093. @
  1094.  
  1095.  
  1096. 1.3
  1097. log
  1098. @removes uumail:<file>.o before backup uumail:<file>
  1099. @
  1100. text
  1101. @d21 3
  1102. d34 1
  1103. a34 1
  1104. static char     *rcsid="$Id: mail.c,v 1.2 1993/09/18 16:47:47 Aussem Exp Aussem $";
  1105. d57 3
  1106. a59 2
  1107. static const char *version = "$VER: mail V1.0 © 1993 by Ralph-Thomas Aussem ("__DATE__","__TIME__")";
  1108. static const int maxretry = 10;
  1109. d294 2
  1110. a295 2
  1111.       printf ("%s: unable to open %s, waiting %d secs\n", argv0, file, retry);
  1112.       sleep (retry);
  1113. @
  1114.  
  1115.  
  1116. 1.2
  1117. log
  1118. @put the "normal" and axsh version in this file (set define AXSH
  1119. for the AXSh Version)
  1120. @
  1121. text
  1122. @d21 4
  1123. d31 1
  1124. a31 1
  1125. static char     *rcsid="$Id: mail.c,v 1.1 1993/09/11 15:01:16 Aussem Exp Aussem $";
  1126. d253 5
  1127. d260 1
  1128. @
  1129.  
  1130.  
  1131. 1.1
  1132. log
  1133. @Initial revision
  1134. @
  1135. text
  1136. @d5 19
  1137. a23 9
  1138.  * Copyright:
  1139.  * This package is freeware.  This means you can copy it freely
  1140.  * as  long as you don't ask any money for it, except perhaps a
  1141.  * nominal fee for copying.  The package is however Copyright ©
  1142.  * Ralph-Thomas   Aussem,  All  Rights  Reserved.   The  author
  1143.  * reservers  the  right  to  change the status of this package
  1144.  * whenever he may find it appropriate.
  1145.  
  1146.  * $Log$
  1147. d27 1
  1148. a27 1
  1149. static char     *rcsid="$Id$";
  1150. d38 8
  1151. d59 10
  1152. d101 43
  1153. d157 4
  1154. d207 1
  1155. a207 1
  1156.   char file[128], puf[128], *text;
  1157. d224 4
  1158. d231 4
  1159. a234 1
  1160.   if(filelength(file)==-1)
  1161. d236 2
  1162. a237 1
  1163.       printf (" No mail-folder for user >>%s<< exists\n",argv[2]);
  1164. d240 3
  1165. a242 7
  1166.   strcpy (puf, "copy ");
  1167.   strcat (puf, file);
  1168.   strcat (puf, " to ");
  1169.   strcat (puf, file);
  1170.   strcat (puf, ".o");
  1171.   rc = system (puf);
  1172.   if (rc)
  1173. d244 3
  1174. a246 2
  1175.       printf ("%s: Unable to create backup file (%s)\n", argv0, puf);
  1176.       exit (10);
  1177. d248 16
  1178. a263 1
  1179.  
  1180. d270 1
  1181. d291 1
  1182. d303 1
  1183. d322 1
  1184. d327 1
  1185. @
  1186.